//
//  Storage.m
//  iSeeColor
//
//  Created by Wyatt Gosling on 10/20/12.
//  Copyright (c) 2012 Wyatt Gosling. All rights reserved.
//

#import "Storage.h"
#import "Dropbox.h"
#import "LocalStorage.h"

@implementation Storage



/*
 Known bugs:
 
 iPhone with wifi:
 (2012/11/12)-Photo will not save to photo library but only to dropbox
 
 */
static Storage *instance;
+ (Storage*) getInstance
{
    NSString *location = [[NSUserDefaults standardUserDefaults] stringForKey:@"storage location"];

    if ( location == nil ) {
        location = @"local";
        [[NSUserDefaults standardUserDefaults] setObject:@"local" forKey:@"storage location"];
        [[NSUserDefaults standardUserDefaults] synchronize];
    }
    if ( [location isEqualToString:@"local"] ) {
        if (instance == nil ||
            ![instance isKindOfClass:[LocalStorage class]] ) {
            instance = [[LocalStorage alloc] init];
        }
    }
    else if ( [location isEqualToString:@"dropbox"] ) {
        if ( instance == nil ||
            ![instance isKindOfClass:[Dropbox class]] ) {
            instance = [[Dropbox alloc] init];
        }
    }
    else {
        [NSException raise:@"This is an unkown storage type" format:@"%@", location];
    }

    return instance;
}

- (void)save:(UIImage *)image
{
   // NSLog(@"This is a dummy function, and should never be called");
    return;
}

@end
